Fk.home = (function() {
	var _homeMenus = null,
		_dragMenu = null;
	
	function _init(){
		_homeMenus = Fk.$('div', Fk.$('homeMenu'));
		[].forEach.call(_homeMenus, function(homeMenu) {
		  Fk.bindEvent(homeMenu, 'dragstart', _handleDragStart);
		  Fk.bindEvent(homeMenu, 'dragenter', _handleDragEnter);
		  Fk.bindEvent(homeMenu, 'dragover', _handleDragOver);
		  Fk.bindEvent(homeMenu, 'dragleave', _handleDragLeave);
		  Fk.bindEvent(homeMenu, 'drop', _handleDrop);
		  Fk.bindEvent(homeMenu, 'dragend', _handleDragEnd);
		});
		
        return false;
	}
	
	function _handleDragStart(e){
		e.dataTransfer.effectAllowed = 'move';
		_dragMenu = this;
		this.addClassName('moving');
		try{e.dataTransfer.setData('text/html', this.innerHTML);}
		catch(err){e.dataTransfer.setData('text', this.innerHTML);}
	}
	
	function _handleDragOver(e){
		if (e.preventDefault) {e.preventDefault();}
		e.dataTransfer.dropEffect = 'move';
		return false;
	}
	
	function _handleDragEnter(e){
		this.addClassName('over');
		return false;
	}
	
	function _handleDragLeave(e){
		this.removeClassName('over');
		return false;
	}
	
	function _handleDrop(e) {
		if (e.stopPropagation) {e.stopPropagation();}
		if (_dragMenu !== this) {
			_dragMenu.innerHTML = this.innerHTML;
			try{this.innerHTML = e.dataTransfer.getData('text/html');}
			catch(err){this.innerHTML = e.dataTransfer.getData('text');}
		}
        _resetState();
		return false;
	}

	function _handleDragEnd(e) {
        _resetState();
		return false;
	}
    
    function _resetState(){
		[].forEach.call(_homeMenus, function (homeMenu) {
			homeMenu.removeClassName('over');
			homeMenu.removeClassName('moving');
		});
    }
	
	return{
        init: _init
    };
}());